package kz.kstu.scantest.app.delegate.impl;

import kz.kstu.scantest.app.delegate.api.AccountDelegate;
import kz.kstu.scantest.app.util.locator.ServiceLocator;
import kz.kstu.scantest.app.util.locator.factory.ServiceLocatorFactory;
import kz.kstu.scantest.business.entity.security.Account;
import kz.kstu.scantest.facade.ejb.api.AccountFacade;

import javax.security.auth.login.LoginException;

/**
 * @author Filipp_Stankevich
 *         created: 08.09.11 14:35
 */
public class AccountDelegateImpl implements AccountDelegate {

    private AccountFacade getAccountFacade(boolean isOnline) {
        ServiceLocator serviceLocator = ServiceLocatorFactory.getServiceLocator(isOnline);
        return serviceLocator.getService(AccountFacade.SERVICE_NAME, AccountFacade.class);
    }

    @Override
    public Account login(String login, String password) throws LoginException {
        return getAccountFacade(false).login(login, password);
    }

    @Override
    public void changePassword(Long accountId, String newPassword) {
        getAccountFacade(false).changePassword(accountId, newPassword);
    }
}
